<template>
  <div class="profile-main">
    <div class="content-header">
      <div class="content-tabs">
        <button 
          v-for="tab in tabs" 
          :key="tab.id"
          :class="['tab-btn', { active: currentTab === tab.id }]"
          @click="$emit('tab-change', tab.id)"
        >
          {{ tab.name }}
          <span class="count" v-if="tab.count">({{ tab.count }})</span>
        </button>
      </div>
      <div class="view-toggle">
        <button 
          class="toggle-btn"
          :class="{ active: isScrollView }"
          @click="toggleView"
          title="切换视图模式"
        >
          <i :class="isScrollView ? 'fas fa-list' : 'fas fa-arrows-alt-v'"></i>
        </button>
      </div>
    </div>

    <div class="content-body" :class="{ 'scroll-view': isScrollView }">
      <!-- 文章列表 -->
      <div v-if="currentTab === 'articles'" class="articles-list">
        <div v-for="article in userArticles" :key="article.id" class="article-item">
          <router-link 
            :to="{ name: 'article', params: { id: article.id }}" 
            class="article-title"
          >
            {{ article.title }}
          </router-link>
          <p class="article-summary">{{ article.summary }}</p>
          <div class="article-meta">
            <span class="publish-time">{{ article.createTime }}</span>
            <div class="article-stats">
              <span class="stat-item">
                <i class="fas fa-comment"></i>
                {{ article.stats.comments }}
              </span>
              <span class="stat-item">
                <i class="fas fa-thumbs-up"></i>
                {{ article.stats.likes }}
              </span>
              <span class="stat-item">
                <i class="fas fa-eye"></i>
                {{ article.stats.views }}
              </span>
            </div>
          </div>
        </div>
      </div>

      <!-- 评论列表 -->
      <div v-else-if="currentTab === 'comments'" class="comments-list">
        <div v-for="comment in userComments" :key="comment.id" class="comment-item">
          <p class="comment-content">{{ comment.content }}</p>
          <div class="comment-meta">
            <router-link 
              :to="{ name: 'article', params: { id: comment.articleId }}" 
              class="article-link"
            >
              评论于：{{ comment.articleTitle }}
            </router-link>
            <span class="comment-time">{{ comment.createTime }}</span>
          </div>
        </div>
      </div>

      <!-- 点赞列表 -->
      <div v-else-if="currentTab === 'likes'" class="likes-list">
        <div v-for="article in likedArticles" :key="article.id" class="article-item">
          <router-link 
            :to="{ name: 'article', params: { id: article.id }}" 
            class="article-title"
          >
            {{ article.title }}
          </router-link>
          <div class="article-meta">
            <span class="author">
              作者：
              <router-link 
                :to="{ name: 'userProfile', params: { id: article.authorId }}"
              >
                {{ article.authorName }}
              </router-link>
            </span>
            <span class="like-time">{{ article.likeTime }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue'
import { ref } from 'vue'

defineProps({
  currentTab: String,
  tabs: Array,
  userArticles: Array,
  userComments: Array,
  likedArticles: Array
})

defineEmits(['tab-change'])

const isScrollView = ref(true)

const toggleView = () => {
  isScrollView.value = !isScrollView.value
}
</script>

<style scoped>
.profile-main {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
}

.content-tabs {
  display: flex;
  padding: 0 20px;
}

.tab-btn {
  padding: 16px 24px;
  border: none;
  background: none;
  color: var(--text-light);
  font-size: 15px;
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
}

.tab-btn.active {
  color: var(--primary-color);
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--primary-color);
}

.count {
  font-size: 13px;
  color: var(--text-lighter);
  margin-left: 4px;
}

/* 视图切换按钮样式 */
.view-toggle {
  padding-right: 20px;
}

.toggle-btn {
  padding: 8px;
  border: none;
  background: none;
  cursor: pointer;
  color: #666;
  border-radius: 4px;
  transition: all 0.3s;
}

.toggle-btn:hover {
  background: #f5f5f5;
  color: var(--primary-color);
}

.toggle-btn.active {
  color: var(--primary-color);
  background: #f0f7ff;
}

.content-body {
  padding: 20px;
  transition: max-height 0.3s;
}

.content-body.scroll-view {
  max-height: 570px;
  overflow-y: auto;
}

/* 自定义滚动条样式 */
.content-body.scroll-view::-webkit-scrollbar {
  width: 6px;
}

.content-body.scroll-view::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.content-body.scroll-view::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 3px;
}

.content-body.scroll-view::-webkit-scrollbar-thumb:hover {
  background: #ccc;
}

.article-item,
.comment-item {
  padding: 16px 0;
  border-bottom: 1px solid var(--border-color);
}

.article-item:last-child,
.comment-item:last-child {
  border-bottom: none;
}

.article-title {
  display: block;
  font-size: 16px;
  color: var(--text-color);
  text-decoration: none;
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.5;
}

.article-summary {
  color: var(--text-light);
  font-size: 14px;
  margin-bottom: 12px;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}

.article-meta,
.comment-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  color: var(--text-lighter);
}

.article-stats {
  display: flex;
  gap: 16px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.comment-content {
  color: var(--text-color);
  margin-bottom: 8px;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}

.article-link {
  color: var(--primary-color);
  text-decoration: none;
}

.article-link:hover {
  text-decoration: underline;
}
</style> 